package com.hspedu.newData.dmsxl.动态规划.基础;

import org.junit.Test;

import java.util.Arrays;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC279完全平方数 {

    public int numSquares(int n) {
        int[] dp = new int[n+1];
        Arrays.fill(dp,n);
        dp[0] = 0;

        for (int i = 1; i <= n; i++) {
            int x = (int)Math.pow(i,0.5);
            for (int j = 1; j <= x; j++) {
                if (i >= j*j){
                    dp[i] = Math.min(dp[i],dp[i-j*j] + 1);
                }
            }
        }
        return dp[n];
    }


    @Test
    public void test() {
        // 测试代码
        int x = numSquares(12);
        int xx1 = numSquares(13);
        int x3 = numSquares(123);
        System.out.println(111);
    }

}
